/**    
 * @package com.liusany.myshop.web.admin 
 * @description : TODO(用一句话描述该包做什么) 
 * @Copyright: Bmcok Corporation 2012    
*/
package com.liusany.myshop.web.admin;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.liusany.modules.orm.Page;
import com.liusany.modules.orm.PropertyFilter;
import com.liusany.myshop.entity.Role;
import com.liusany.myshop.service.RoleService;

/**   
 * @filename ：RoleController.java   
 * @description : TODO(用一句话描述该类做什么) 
 * @version ：   V 1.0
 * @author : liusany
 * @create : 2012-5-18 下午2:50:53  
 * @Copyright: Bmcok Corporation 2012    
 * 
 * Modification History:
 * 	Date			Author			Version			Description
 *--------------------------------------------------------------
 *2012-5-18 下午2:50:53
 */
@Controller
@RequestMapping(value = "/admin/role")
public class RoleController extends BaseCopntroller{

	@Resource
	private RoleService roleService;
	
	/**
	 * 角色列表
	 * @param model
	 * @param pager
	 * @return
	 */
	@RequestMapping(value = { "list", "" })
	public String list(Model model,Page<Role> pager,HttpServletRequest request) {
		try {
			List<PropertyFilter> filters = PropertyFilter.buildFromHttpRequest(request);
			//设置默认排序方式
			if (!pager.isOrderBySetted()) {
				pager.setOrderBy("id");
			}
			pager = roleService.findByPage(pager, filters);
		} catch (Exception e) {
			e.printStackTrace();
		}
		model.addAttribute("pager", pager);
		return "admin/role_list";
	}
	
	@RequestMapping(value = "create", method = RequestMethod.GET)
	public String createForm(Model model,HttpServletRequest request) {
		model.addAttribute("role", new Role());
		return "admin/role_input";
	}
	
	@RequestMapping(value = "save", method = RequestMethod.POST)
	public String save(Role role,Model model) {
		roleService.saveRole(role);
		setRedirectInfo("admin/role/list", "创建权限组" + role.getName() + "成功", model);
		return SUCCESS;
	}
}
